import { Component } from 'react'
import { View, Text} from '@tarojs/components'
import {Async} from "utils"
import Taro from "@tarojs/taro"

import './wechat.scss'
import {LoginByOAuth2} from "../../api/LoginByOAuth2";
import {MainApp} from "../../MainApp";


export default class Wechat extends Component {
  componentDidMount () {
    if (window&&window.location) {
      const w = window.location.href.indexOf('?');
      const j =  window.location.href.indexOf('#');
      let href = window.location.href;
      if (w !== -1 && j > w) {
        href =  window.location.href.substr(0, w) +
          window.location.href.substr(j,  window.location.href.length) +  window.location.search;
        window.location.href = href;
        return
      }
    }

    Async(async ()=> {
      const instance = Taro.getCurrentInstance();
      await LoginByOAuth2(MainApp.plugin().getMainNet(), instance.router?.params["code"]!)
    })
  }

  componentWillUnmount () { }

  componentDidShow () { }

  componentDidHide () { }

  render () {
    return (
      <View className='index'>
        <Text>登录中</Text>
      </View>
    )
  }
}
function WithFormUrlEncodedBody(): import("foundation").HttpOption {
    throw new Error('Function not implemented.');
}

function WithoutToken(): import("foundation").HttpOption {
    throw new Error('Function not implemented.');
}

